<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Young粉认证</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="applicable-device" content="mobile">
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=yes, width=device-width">
	<meta name="format-detection" content="telephone=no" />
    <link rel="stylesheet" href="css/ui-selectbox.css">
	<link rel="stylesheet" href="css/style.css">
	<script src="js/jquery.js"></script>
    <script src="js/common.js"></script>
    <script src="js/selectbox-min.js"></script>
    <script type="text/javascript">
	   $(document).ready(function(){
		   showYear();
			$.ajax({
				type: "post",
			 	url: "/personalcenter/signupuser",
			    dataType: "json",
				success: function (data) {
			    	if(data.result==0){
			    		$("#sel-school").html("<option value='' selected='selected'>请选择学校校区（必选）</option>"+data.school);
			    		$("#sel-building").html("<option value='' selected='selected'>楼</option>");
			    		 $('select').each(function () {
			    	          selectbox(this);
			    	        });
			    	}else{
			    		window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe643cc1b34aa8f25&redirect_uri=http%3a%2f%2fa6.189young.com%2fpersonalcenter%2fcheckuser&response_type=code&scope=snsapi_base&state=1#wechat_redirect';
			    	}
			    }
			}); 
	 	});
	   
	   function showYear(){
		   var year=new Date().getFullYear(); 
		   $("#sel-year").html("<option value=''>入学年份</option><option value='"+year+"'>"+year+"</option><option value='"+(year-1)+"'>"+(year-1)+"</option><option value='"+(year-2)+"'>"+(year-2)+"</option><option value='"+(year-3)+"'>"+(year-3)+"</option><option value='"+(year-4)+"'>"+(year-4)+"</option><option value='"+(year-5)+"'>"+(year-5)+"</option><option value='"+(year-6)+"'>"+(year-6)+"</option><option value='"+(year-7)+"'>"+(year-7)+"</option>");
		}
	   
	   function changeSchool(){
		   $.ajax({
				type: "post",
			 	url: "/personalcenter/signupschool",
			 	data: {school:$.trim($("#sel-school").val())},
			    dataType: "json",
				success: function (data) {
			    	if(data.result==0){
			    		$("#sel-building").html(data.school);
			    		$('select').each(function () {
			    	          selectbox(this);
			    	        });
			    	}else{
			    		window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe643cc1b34aa8f25&redirect_uri=http%3a%2f%2fa6.189young.com%2fpersonalcenter%2fcheckuser&response_type=code&scope=snsapi_base&state=1#wechat_redirect';
			    	}
			    }
			}); 
	   }
    </script>
</head>
<body>
    <div class="page bg-yellow">
        <a href="javascript:history.go(-1);" class="btn-back posa">返回</a>
        <div class="login-form">
          <div class="login-raw"><input type="tel" name="usermobile" id="usermobile" placeholder="请输入您的手机号码（必填）"></div>
          <div class="login-raw clearfix"><input type="text" name="lockcode" id="lockcode" class="fl txt-yzm" placeholder="请输入图形验证码"><img onclick="changelockcode()" class="fr btn-yzm" id="lockimg" src="/personalcenter/lockcode"></img></div>
          <div class="login-raw clearfix"><input type="tel" name="usercode" id="usercode" class="fl txt-yzm" placeholder="请输入短信验证码"><button onclick="getcode()" class="fr btn-yzm" id="button">获得短信码</button></div>
          <div class="login-raw">
            <select id="sel-school" onchange="changeSchool()">
            </select>
          </div>
          <div class="login-raw">
            <select id="sel-building">
            </select>
          </div>
          <div class="login-raw">
            <select id="sel-year">
            </select>
          </div>
          <div class="login-raw"><input type="text" name="username" id="username" placeholder="请输入您的姓名或昵称"></div>
          <div class="login-raw"><input type="text" name="usermajor" id="usermajor" placeholder="请输入您的专业"></div>
          <div class="form-ps">小Young提醒：<br>为保证服务的质量及正确，请保证个人信息正确哦，校区和楼将影响宽带相关服务，如果搬迁请及时更新。</div>
          <div class="form-rule tc"><input type="checkbox" id="form-rule-txt"><label for="form-rule-txt">我已经阅读并同意</label>《<a href="signup_rule.html">用户注册协议</a>》</div>
          <div class="tc btn-bottom"><button onclick="commit()" class="btn btn-login" style="width:100%" id="commit">确认提交</button></div>
        </div>

        <div class="out-mask"></div>
        <!-- 注册成功弹窗 -->
        <div class="out-box out-welcome">
          <div class="out-box-inner">
            <h2 class="yellow-title tc">注册成功!</h2>
            <p class="out-box-msg tc">欢迎来到Young粉大家庭～</p>
            <div class="tc out-btn-row"><a href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe643cc1b34aa8f25&redirect_uri=http%3a%2f%2fa6.189young.com%2fpersonalcenter%2fcheckuser&response_type=code&scope=snsapi_base&state=1#wechat_redirect" class="btn btn-yellow">返回首页</a></div>
          </div>
        </div>
        
    </div>

    <script>
    function changelockcode(){
    	$("#lockimg").attr("src","/personalcenter/lockcode");
    }
    
	function getcode(){
	  if($.trim($("#usermobile").val()) == ""){
	        alert("手机号码不能为空！");
	        return false;
	    }
	    if (!$("#usermobile").val().match(/^1[3,4,5,6,7,8,9]\d{9}$/)) { 
	        alert("请正确填写手机号码！");
	        return false;
	    }
	    if($.trim($("#lockcode").val()) == ""){
	        alert("图形验证码不能为空！");
	        return false;
	    }
	    //向后台发送处理数据
		//短信验证
		wait();
		$.ajax({ 
	      type: "post", 
	      url: "/personalcenter/message", 
	      data: {mobile:$.trim($("#usermobile").val()),lockcode:$.trim($("#lockcode").val())},
	      dataType: "json", 
	      success: function (data) {
	    	    if(data.result==3){
	    	    	changelockcode();
	    	    	alert("请输入正确的图形验证码！");
	    	    }else{
	    	    	if(data.result==0){
		   	   		    changelockcode();
		   		   		alert("短信已发送！");
		   	   		}else{
		   	   			changelockcode();
		      			alert("短信发送失败！");
		   	   		}
	    	    }
	      }, 
	      error: function (XMLHttpRequest, textStatus, errorThrown) {
	    	 changelockcode();
	         alert("短信发送失败"); 
	         return false;
	      } 
	    });  
  	}
  function commit(){
	  var grade;
	  var major;
	  if($.trim($("#usermobile").val()) == ""){
	        alert("手机号码不能为空！");
	        return false;
	    }
	    if (!$("#usermobile").val().match(/^1[3,4,5,6,7,8,9]\d{9}$/)) { 
	        alert("请正确填写手机号码！");
	        return false;
	    }
	    if($.trim($("#lockcode").val()) == ""){
	        alert("图形验证码不能为空！");
	        return false;
	    }
	    if($.trim($("#usercode").val()) == ""){
	        alert("短信码不能为空！");
	        return false;
	    }
	    if($.trim($("#sel-school").val()) == ""){
	        alert("学校不能为空！");
	        return false;
	    }
	    if($.trim($("#sel-year").val()) == ""){
	        alert("入学年份不能为空！");
	        return false;
	    }
	    if($.trim($("#username").val()) == ""){
	        grade="";
	    }else{
	    	grade=$.trim($("#username").val());
	    }
	    if($.trim($("#usermajor").val()) == ""){
	       	major="";
	    }else{
	    	major=$.trim($("#usermajor").val());
	    }
	    if (!$("#form-rule-txt").prop('checked')) { 
	        alert("请阅读《。。。》并勾选“我已阅读...”！");
	        return false;
	    } 
	    $("#commit").css({'color':'#999'});
		$("#commit").css({'background-color':'#eee'});
	    $("#commit").attr('disabled',true);
	  //向后台发送处理数据验证
		$.ajax({ 
	      type: "post", 
	      url: "/personalcenter/saveuser", 
	      data: {mobile:$.trim($("#usermobile").val()),lockcode:$.trim($("#lockcode").val()),coder:$.trim($("#usercode").val()),school:$.trim($("#sel-school").val()),building:$.trim($("#sel-building").val()),useryear:$.trim($("#sel-year").val()),username:grade,usermajor:major},
	      dataType: "json", 
	      success: function (data) { 
	   	   		if(data.result==0){
	   	   		    boxIn($('.out-welcome'));
	   	   		}else if(data.result==1){
	   	   			changelockcode();
	      			alert("请填写正确手机号及验证码！");
	      			$("#commit").css({'background-color':'#a4df8f'});
	      			$("#commit").css({'color':'#fff'});
	      			$("#commit").removeAttr('disabled');
	   	   		}else if(data.result==4){
	   	   			changelockcode();
	   	   			alert("请输入正确的图形验证码！");
	   	   			$("#commit").css({'background-color':'#a4df8f'});
	   	   			$("#commit").css({'color':'#fff'});
	   	   			$("#commit").removeAttr('disabled');
	   	   		}else if(data.result==2){
	   	   			changelockcode();
	   	   			alert("请先发送短信验证码！");
	   	   			$("#commit").css({'background-color':'#a4df8f'});
	   	   			$("#commit").css({'color':'#fff'});
	   	   			$("#commit").removeAttr('disabled');
	   	   		}else{
	   	   			if(data.result==8){
	   	   				alert("你已经是Young粉啦！你认证的手机号为"+data.phone.replace(/(\d{3})\d{6}(\d{2})/,'$1******$2')+"，如有问题，微信联系小Young哟!");
	   	   				window.location.href="index.html";
	   	   			}else{
	   	   				alert("请从正确的入口进行认证！");
	   	   				window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe643cc1b34aa8f25&redirect_uri=http%3a%2f%2fa6.189young.com%2fpersonalcenter%2fcheckuser&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
	   	   			}		
	   	   		}
	      }, 
	      error: function (XMLHttpRequest, textStatus, errorThrown) { 
	    	 changelockcode(); 
	         alert("提交失败!"); 
	         return false;
	      } 
	    });  
  }
  function wait(){
	    var secs = 120; 
	    var wait = secs * 1000;
	    var i = "";
	    for (i = 1; i <= (wait / 1000); i++) {
	        window.setTimeout("doUpdate(" + i + ","+ wait +")", i * 1000);
	    }
	}

	function doUpdate(num,wait) {
	   if (num == (wait / 1000)) {
	   		 $("#button").removeAttr('disabled').text("获取验证码");
	   } else {
	       	var wut = (wait / 1000) - num;
	       	$("#button").text(wut+"秒").attr('disabled',true);
	   }
	}
    </script>

    <!--百度数据统计-->
    <script>var _hmt = _hmt || [];(function() {var hm = document.createElement("script");hm.src="https://hm.baidu.com/hm.js24866553cf6bdd25afcd437091f96447";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s);})();</script>

</body>
</html>
















